<?php

/**
*	修改个人资料
*
*/

//包含公共文件
include '../../common/common.php';

//接收post的传值
//var_dump($_POST);
$realname = trim($_POST['realname']);
$sex 	 = trim($_POST['sex']);
$place   = trim($_POST['place']);
$qq       = trim($_POST['qq']);
$year    = trim($_POST['birthyear']);
$month = trim($_POST['birthmonth']);
$day     = trim($_POST['birthday']);
$birthday = strtotime("$year-$month-$day");

// var_dump($realname);
// var_dump($sex);	 
// var_dump($place);   
// var_dump($qq);         
// var_dump($birthday);

//判断真实姓名是否为空		//if (!0) { echo '0是false'; }
if (!$realname) {

	exit('真实姓名不得为空<br /> <a href="'  . $_SERVER['HTTP_REFERER'] .'">返回上一页</a>');
}

//判断性别
if (!$sex) {

	$sex = 0;
}

//判断生日是否为空
if  (!$year  || !$month || !$day) {

	exit('生日的年,月,日均不得为空<br /> <a href="'  . $_SERVER['HTTP_REFERER'] .'">返回上一页</a>');
}

//判断籍贯是否为空
if (!$place) {

	exit('籍贯不得为空<br /> <a href="'  . $_SERVER['HTTP_REFERER'] .'">返回上一页</a>');
}

//判断qq号是否为空
if (!$qq) {

	exit('qq号码不得为空<br /> <a href="'  . $_SERVER['HTTP_REFERER'] .'">返回上一页</a>');
}

//修改数据库
$username = $_COOKIE['username'];

$data = [
	'realname' => "$realname",
	'sex'         => $sex,
	'birthday'  => $birthday,
	'place'      => "$place",
	'qq'          => $qq
];
//var_dump($data);
$resPer = myUpdate($link , DB_TABLE_USER , $data , "username = '$username'");
// var_dump($resPer);

if ($resPer && mysqli_affected_rows($link)) {

	echo '修改成功';
} else {

	echo '修改失败';
}

//跳转到上一页
header('refresh:1;url=' . $_SERVER['HTTP_REFERER']);